home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ScanImage3 / ScanImage3.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  9.7 KB  |  449 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLEncoder;
  16.  
  17. public class ScanImage3 extends Applet implements Runnable, MouseListener {
  18.    private Thread thread;
  19.    private Image image;
  20.    private Image buffer;
  21.    // $FF: renamed from: b java.awt.Graphics
  22.    private Graphics field_0;
  23.    private boolean loaded = false;
  24.    private boolean move = true;
  25.    // $FF: renamed from: on boolean
  26.    private boolean field_1 = true;
  27.    // $FF: renamed from: wi int
  28.    private int field_2;
  29.    // $FF: renamed from: he int
  30.    private int field_3;
  31.    private int wi_im;
  32.    private int he_im;
  33.    private int pause;
  34.    private double phi;
  35.    // $FF: renamed from: X int
  36.    private int field_4;
  37.    // $FF: renamed from: Y int
  38.    private int field_5;
  39.    // $FF: renamed from: r int
  40.    private int field_6;
  41.    private int r_lim = 100;
  42.    private int r_step = 4;
  43.    private String image_string;
  44.    private String statusBarText;
  45.    private AudioClip sound;
  46.    private AudioClip clicSound;
  47.    private AudioClip enterSound;
  48.    private boolean loopSound;
  49.    private String link;
  50.    // $FF: renamed from: fm java.awt.FontMetrics
  51.    private FontMetrics field_7;
  52.    private String enterText;
  53.    private boolean isEnterTextEnabled;
  54.    private int wiEnterText;
  55.    private int enterTextHeight;
  56.    private Color enterTextColor;
  57.    // $FF: renamed from: z int
  58.    private int field_8;
  59.    private int zMax;
  60.    private int nTetaStep;
  61.  
  62.    public String getAppletInfo() {
  63.       return "Name: ScanImage3\r\nAuthor: Taiji Software\r\n";
  64.    }
  65.  
  66.    public ScanImage3() {
  67.       this.move = true;
  68.       this.pause = 50;
  69.       this.r_lim = 100;
  70.       this.r_step = 10;
  71.       ((Component)this).addMouseListener(this);
  72.       this.nTetaStep = 50;
  73.       this.zMax = 15;
  74.    }
  75.  
  76.    public void register() {
  77.       try {
  78.          URL u = new URL("http://www.taijisoftware.com");
  79.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  80.       } catch (Exception e) {
  81.          System.out.println(e);
  82.          this.stop();
  83.       }
  84.    }
  85.  
  86.    public void init() {
  87.       String codeBase = null;
  88.  
  89.       try {
  90.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  91.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  92.          codeBase = codeBase.toUpperCase();
  93.       } catch (Exception var9) {
  94.       }
  95.  
  96.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  97.          String regCode = ((Applet)this).getParameter("registration_code");
  98.          if (regCode == null) {
  99.             regCode = ((Applet)this).getParameter("reg_domain");
  100.             if (regCode == null) {
  101.                this.register();
  102.             } else {
  103.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  104.                   codeBase = "WWW." + codeBase;
  105.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  106.                   codeBase = codeBase.substring(4);
  107.                }
  108.  
  109.                char[] chars = new char[codeBase.length()];
  110.                codeBase.getChars(0, codeBase.length(), chars, 0);
  111.                String key = new String("haricot");
  112.                char[] chars2 = new char[key.length()];
  113.                key.getChars(0, key.length(), chars2, 0);
  114.  
  115.                for(int i = 0; i < codeBase.length(); ++i) {
  116.                   int j;
  117.                   if (i >= key.length()) {
  118.                      j = i - key.length() * (i / key.length());
  119.                   } else {
  120.                      j = i;
  121.                   }
  122.  
  123.                   chars[i] += chars2[j];
  124.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  125.                }
  126.  
  127.                String res = new String(chars);
  128.                if (!res.equalsIgnoreCase(regCode)) {
  129.                   this.register();
  130.                }
  131.             }
  132.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  133.             this.register();
  134.          }
  135.       }
  136.  
  137.       this.getParameters();
  138.       if (this.sound != null) {
  139.          if (this.loopSound) {
  140.             this.sound.loop();
  141.             return;
  142.          }
  143.  
  144.          this.sound.play();
  145.       }
  146.  
  147.    }
  148.  
  149.    public void getParameters() {
  150.       this.field_2 = ((Component)this).getSize().width;
  151.       this.field_3 = ((Component)this).getSize().height;
  152.       String s = ((Applet)this).getParameter("pause");
  153.       if (s != null) {
  154.          this.pause = Integer.parseInt(s);
  155.       }
  156.  
  157.       s = ((Applet)this).getParameter("r_lim");
  158.       if (s != null) {
  159.          this.r_lim = Integer.parseInt(s);
  160.       }
  161.  
  162.       s = ((Applet)this).getParameter("r_step");
  163.       if (s != null) {
  164.          this.r_step = Integer.parseInt(s);
  165.       }
  166.  
  167.       s = ((Applet)this).getParameter("zoom_amplitude");
  168.       if (s != null) {
  169.          this.zMax = Integer.parseInt(s);
  170.       }
  171.  
  172.       s = ((Applet)this).getParameter("zoom_steps_number");
  173.       if (s != null) {
  174.          this.nTetaStep = Integer.parseInt(s);
  175.       }
  176.  
  177.       this.image_string = ((Applet)this).getParameter("image");
  178.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  179.       s = ((Applet)this).getParameter("sound_name");
  180.       if (s != null) {
  181.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  182.       }
  183.  
  184.       s = ((Applet)this).getParameter("loop_sound");
  185.       if (s != null) {
  186.          if (s.equals("yes")) {
  187.             this.loopSound = true;
  188.          } else {
  189.             this.loopSound = false;
  190.          }
  191.       }
  192.  
  193.       s = ((Applet)this).getParameter("clic_sound_name");
  194.       if (s != null) {
  195.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  196.       }
  197.  
  198.       s = ((Applet)this).getParameter("enter_sound_name");
  199.       if (s != null) {
  200.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  201.       }
  202.  
  203.       this.link = ((Applet)this).getParameter("link");
  204.       this.enterText = ((Applet)this).getParameter("enter_text");
  205.       s = ((Applet)this).getParameter("enter_text_height");
  206.       if (s != null) {
  207.          this.enterTextHeight = Integer.parseInt(s);
  208.       }
  209.  
  210.       this.enterTextColor = this.getColor("enter_text_color");
  211.       if (this.enterTextColor == null) {
  212.          this.enterTextColor = Color.white;
  213.       }
  214.  
  215.    }
  216.  
  217.    public Color getColor(String param) {
  218.       String s = ((Applet)this).getParameter(param);
  219.       if (s != null) {
  220.          if (s.substring(0, 1).equals("#")) {
  221.             s = s.substring(1);
  222.             int i = Integer.parseInt(s, 16);
  223.             return new Color(i);
  224.          } else {
  225.             return null;
  226.          }
  227.       } else {
  228.          return null;
  229.       }
  230.    }
  231.  
  232.    public void paint(Graphics g) {
  233.       if (this.loaded) {
  234.          this.field_0.clearRect(0, 0, this.field_2, this.field_3);
  235.          this.field_0.drawImage(this.image, 0, 0, this.field_2, this.field_3, this.field_4 - this.field_8, this.field_5 - this.field_8, this.field_4 + this.field_2 + this.field_8, this.field_5 + this.field_3 + this.field_8, this);
  236.          if (this.isEnterTextEnabled) {
  237.             this.field_0.drawString(this.enterText, (this.field_2 - this.wiEnterText) / 2, this.field_3 / 2);
  238.          }
  239.  
  240.          g.drawImage(this.buffer, 0, 0, this);
  241.       }
  242.  
  243.    }
  244.  
  245.    public void update(Graphics g) {
  246.       this.paint(g);
  247.    }
  248.  
  249.    public void start() {
  250.       if (this.thread == null) {
  251.          this.move = true;
  252.          this.thread = new Thread(this);
  253.          this.thread.start();
  254.       }
  255.  
  256.    }
  257.  
  258.    public void stop() {
  259.       if (this.thread != null) {
  260.          this.move = false;
  261.          this.thread = null;
  262.       }
  263.  
  264.       if (this.sound != null) {
  265.          this.sound.stop();
  266.       }
  267.  
  268.    }
  269.  
  270.    public void run() {
  271.       if (!this.loaded) {
  272.          MediaTracker tracker = new MediaTracker(this);
  273.          this.image = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.image_string);
  274.          tracker.addImage(this.image, 0);
  275.  
  276.          try {
  277.             tracker.waitForAll();
  278.             this.loaded = !tracker.isErrorAny();
  279.          } catch (Exception e) {
  280.             System.out.println(e);
  281.          }
  282.  
  283.          if (!this.loaded) {
  284.             this.stop();
  285.          }
  286.       }
  287.  
  288.       this.wi_im = this.image.getWidth(this);
  289.       this.he_im = this.image.getHeight(this);
  290.       this.buffer = ((Component)this).createImage(this.field_2, this.field_3);
  291.       this.field_0 = this.buffer.getGraphics();
  292.       this.field_0.setColor(this.enterTextColor);
  293.       String fontName = ((Applet)this).getParameter("enter_text_font");
  294.       if (fontName == null) {
  295.          fontName = "TimesRoman";
  296.       }
  297.  
  298.       int style = 1;
  299.       String s = ((Applet)this).getParameter("enter_text_style");
  300.       if (s != null) {
  301.          if (s.equals("bold")) {
  302.             style = 1;
  303.          } else if (s.equals("italic")) {
  304.             style = 2;
  305.          } else if (s.equals("bold_italic")) {
  306.             style = 3;
  307.          } else {
  308.             style = 0;
  309.          }
  310.       }
  311.  
  312.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  313.       this.field_7 = this.field_0.getFontMetrics();
  314.       if (this.enterText != null) {
  315.          this.wiEnterText = this.field_7.stringWidth(this.enterText);
  316.       }
  317.  
  318.       int X_last = 0;
  319.       int Y_last = 0;
  320.       int zStep = 1;
  321.       double teta = (double)0.0F;
  322.       double tetaStep = Math.PI / (double)((float)this.nTetaStep);
  323.  
  324.       while(this.move) {
  325.          while(this.field_1) {
  326.             this.phi = (double)((int)((double)360.0F * Math.random()));
  327.             this.field_6 = 0;
  328.             int r_max = (int)((double)(this.r_lim / 2) * Math.random()) + this.r_lim / 2;
  329.  
  330.             while(this.field_6 <= r_max) {
  331.                this.field_8 += zStep;
  332.                this.field_8 = (int)((double)this.zMax * Math.sin(teta));
  333.                teta += tetaStep;
  334.                this.field_4 += (int)((double)this.r_step * Math.cos(this.phi / (double)180.0F * Math.PI));
  335.                this.field_5 += (int)((double)this.r_step * Math.sin(this.phi / (double)180.0F * Math.PI));
  336.                if (this.field_4 - this.field_8 < 0 || this.field_5 - this.field_8 < 0 || this.field_4 + this.field_2 + this.field_8 > this.wi_im || this.field_5 + this.field_3 + this.field_8 > this.he_im) {
  337.                   this.field_4 = X_last;
  338.                   this.field_5 = Y_last;
  339.                   break;
  340.                }
  341.  
  342.                X_last = this.field_4;
  343.                Y_last = this.field_5;
  344.                ((Component)this).repaint();
  345.  
  346.                try {
  347.                   Thread.sleep((long)this.pause);
  348.                } catch (InterruptedException var14) {
  349.                   this.stop();
  350.                }
  351.  
  352.                this.field_6 += this.r_step;
  353.                if (!this.field_1) {
  354.                   break;
  355.                }
  356.             }
  357.          }
  358.  
  359.          try {
  360.             Thread.sleep(100L);
  361.          } catch (InterruptedException var12) {
  362.             this.stop();
  363.          }
  364.       }
  365.  
  366.    }
  367.  
  368.    public URL giveURL(String url) {
  369.       try {
  370.          if (url.toUpperCase().startsWith("HTTP")) {
  371.             return new URL(url);
  372.          } else if (url.toUpperCase().startsWith("FTP")) {
  373.             int p = url.indexOf(":");
  374.             int p2 = url.indexOf(":", p + 1);
  375.             if (p2 != -1) {
  376.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  377.             }
  378.  
  379.             p = url.indexOf("%40");
  380.             if (p != -1) {
  381.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  382.             }
  383.  
  384.             return new URL(url);
  385.          } else {
  386.             return new URL(((Applet)this).getCodeBase(), url);
  387.          }
  388.       } catch (MalformedURLException e) {
  389.          System.out.println(e);
  390.          return null;
  391.       }
  392.    }
  393.  
  394.    public void mouseClicked(MouseEvent e) {
  395.    }
  396.  
  397.    public void mouseEntered(MouseEvent e) {
  398.       if (this.enterText != null) {
  399.          this.isEnterTextEnabled = true;
  400.          ((Component)this).repaint();
  401.       }
  402.  
  403.       if (this.statusBarText != null) {
  404.          ((Applet)this).showStatus(this.statusBarText);
  405.       }
  406.  
  407.       if (this.enterSound != null) {
  408.          this.enterSound.play();
  409.       }
  410.  
  411.       if (this.link != null) {
  412.          ((Component)this).setCursor(new Cursor(12));
  413.       }
  414.  
  415.    }
  416.  
  417.    public void mouseExited(MouseEvent e) {
  418.       if (this.isEnterTextEnabled) {
  419.          this.isEnterTextEnabled = false;
  420.          ((Component)this).repaint();
  421.       }
  422.  
  423.       if (this.link != null) {
  424.          ((Component)this).setCursor(new Cursor(0));
  425.       }
  426.  
  427.    }
  428.  
  429.    public void mousePressed(MouseEvent e) {
  430.       if (this.clicSound != null) {
  431.          this.clicSound.play();
  432.       }
  433.  
  434.       if (this.link != null) {
  435.          String target = ((Applet)this).getParameter("target");
  436.          if (target == null) {
  437.             target = "_blank";
  438.          }
  439.  
  440.          URL u = this.giveURL(this.link);
  441.          ((Applet)this).getAppletContext().showDocument(u, target);
  442.       }
  443.  
  444.    }
  445.  
  446.    public void mouseReleased(MouseEvent e) {
  447.    }
  448. }
  449.